package com.hgsoft.pubsv.component.xxlrpc.config;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import com.hgsoft.pubsv.component.xxlrpc.properties.XxlRpcProperties;
import com.xxl.rpc.core.registry.impl.XxlRpcAdminRegister;
import com.xxl.rpc.core.remoting.invoker.impl.XxlRpcSpringInvokerFactory;

import lombok.extern.slf4j.Slf4j;

/**
 * rpc 客户端bean加载
 * @author saint
 */
@Slf4j
public class XxlRpcInvokerConfig {

	@Autowired
	private XxlRpcProperties xxlRpcProperties;

    @SuppressWarnings("serial")
	@Bean
    public XxlRpcSpringInvokerFactory xxlJobExecutor() {
        XxlRpcSpringInvokerFactory invokerFactory = new XxlRpcSpringInvokerFactory();
        invokerFactory.setServiceRegistryClass(XxlRpcAdminRegister.class);
        invokerFactory.setServiceRegistryParam(new HashMap<String, String>() {{
            put(XxlRpcAdminRegister.ADMIN_ADDRESS, xxlRpcProperties.getAdminAddress());
            put(XxlRpcAdminRegister.ENV, xxlRpcProperties.getEnv());
            put(XxlRpcAdminRegister.ACCESS_TOKEN, xxlRpcProperties.getAccessToken());
            put(XxlRpcAdminRegister.BIZ, xxlRpcProperties.getBiz());
        }});

        log.info(">>>>>>>>>>> xxl-rpc invoker config init finish.");
        return invokerFactory;
    }

}
